import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

/**
 *
 */
public class RiverPanel extends JPanel{
    private Game game;
	
	private JButton btnFord;
	private JButton btnFloat;

	private JButton btnFerry;
	private JLabel lblWidth;
	private JLabel lblDepth;


        
	/**
	 * Creates the turn screen.
	 * 
	 * @param g - the current game.
	 */
	public RiverPanel(Game g) {

		game = g;
                
		setLayout(null);
		
		setBorder(new EmptyBorder(5, 5, 5, 5));
		
		btnFord = new JButton("Ford");
		btnFord.setBounds(569, 451, 158, 60);
		add(btnFord);
		btnFord.addActionListener(new ButtonListener());
		
		
		btnFloat = new JButton("Float");
		btnFloat.setBounds(533, 245, 137, 23);
		add(btnFloat);
		btnFloat.addActionListener(new ButtonListener());
		
		JLabel lblRiver = new JLabel("River Crossing");
		lblRiver.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblRiver.setHorizontalAlignment(SwingConstants.CENTER);
		lblRiver.setBounds(309, 21, 158, 23);
		add(lblRiver);
		

		
		btnFerry = new JButton("Ferry");
		btnFerry.setBounds(581, 139, 89, 23);
		add(btnFerry);
		btnFerry.addActionListener(new ButtonListener());
		btnFerry.setEnabled(false);

		JLabel lblRiverDepth = new JLabel("River Depth: ");
		lblRiverDepth.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblRiverDepth.setBounds(93, 143, 137, 23);
		add(lblRiverDepth);
		
		JLabel lblRiverWidth = new JLabel("River Width: ");
		lblRiverWidth.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblRiverWidth.setBounds(93, 181, 137, 19);
		add(lblRiverWidth);
		
		
		lblWidth = new JLabel("");
		lblWidth.setBounds(242, 184, 70, 15);
		add(lblWidth);

		lblDepth = new JLabel("");
		lblDepth.setBounds(242, 147, 70, 15);
		add(lblDepth);
		
	}
	
	/**
	 * Updates the labels on the panel that show remaining food 
	 * and distance traveled.
	 * 
	 * @param distanceTraveled - Number of miles traveled so far
	 * @param foodLeft - Pounds of food remaining.
	 */
	public void updatePanel(int depth, int width, boolean hasFerry){
		
		lblWidth.setText(Integer.toString(width));
		lblDepth.setText(Integer.toString(depth));
		btnFerry.setEnabled(hasFerry);
	}
	
        /**
         * Handles the on-click actions of the river panel's buttons.
         */
	class ButtonListener implements ActionListener
	{

		@Override
		public void actionPerformed(ActionEvent e) 
		{
			if(e.getSource().equals(btnFord))
			{
                            //System.out.println("Ford");
                            game.riverCrossing("Ford");
			}

			else if(e.getSource().equals(btnFloat)) {
                            //System.out.println("Float");
                            game.riverCrossing("Float");
			}

			else //source == Ferry button
			{
                            //System.out.println("Ferry");
                            game.riverCrossing("Ferry");
			}
		}
	}
}
